<template>
  <div id="target">
    <el-table
      v-if="noResponse"
      v-loading="loading"
      style="width: 100%;height: 419px;margin: 10px auto;z-index: 1">
    </el-table>
    <el-empty v-if="isEmpty" :image-size="200"></el-empty>
    <div class="cardBox" v-if="!isSearch && !isEmpty" v-for="(item, index) in contentData" :key="index">
      <div class="content">
        <router-link target="_blank" :to="{path:'/worksDisplayPage',query:{workId:item.errorId}}">
          <div class="cardHead">
            <div class="cardHead-title">
              {{item.title}}
            </div>
            <div class="cardHead-describ">
              {{item.errorDescribe}}
            </div>
          </div>
        </router-link>
        <div class="cardDetial">
          <div class="cardDetial-pubTime"><i class="iconfont icon-shijian cards-bottom-icn"></i>
            {{item.publishTime}}
          </div>
          <div class="cardDetial-act"><i class="iconfont icon-huoyue cards-bottom-icn" style="font-size: 20px;"></i>{{item.act}}</div>
          <div class="cardDetial-star"><i class="iconfont icon-star cards-bottom-icn" style="font-size: 22px;"></i>{{item.star}}</div>
          <div class="cardDetial-classify"><i class="iconfont icon-leibie cards-bottom-icn" style="font-size: 16px;"></i>{{item.label}}</div>
        </div>
      </div>

      <div class="controller">
        <div class="edit">
          <router-link target="_blank" :to="{path:'/publishPage/error',query:{workId:item.errorId}}" :title="$t('userAdmin.works.error.edit')">
            <i class="iconfont icon-bianji"></i>
          </router-link>
        </div>
        <div class="delete">
          <a href="javascript:;" :title="$t('userAdmin.works.error.delete')" @click="deleteArticle(item.errorId)">
            <i class="iconfont icon-shanchu"></i>
          </a>
        </div>
      </div>
    </div>
    <div class="cardBox" v-if="isSearch && !isEmpty" v-for="(item,index) in contentData" :key="index">
      <div class="content">
        <router-link target="_blank" :to="{path:'/worksDisplayPage',query:{workId:item.articleId}}">
          <div class="cardHead">
            <div class="cardHead-title" v-html="item.title"></div>
            <div class="cardHead-describ">
              {{item.titleDescribe}}
            </div>
          </div>
        </router-link>
        <div class="cardDetial">
          <div class="cardDetial-pubTime"><i class="iconfont icon-shijian cards-bottom-icn"></i>
            {{item.date}}
          </div>
          <div class="cardDetial-act"><i class="iconfont icon-huoyue cards-bottom-icn" style="font-size: 20px;"></i>{{item.act}}</div>
          <div class="cardDetial-star"><i class="iconfont icon-star cards-bottom-icn" style="font-size: 22px;"></i>{{item.star}}</div>
          <div class="cardDetial-classify"><i class="iconfont icon-leibie cards-bottom-icn" style="font-size: 16px;"></i>{{item.label}}</div>
        </div>
      </div>

      <div class="controller">
        <div class="edit">
          <router-link target="_blank" :to="{path:'/publishPage/error',query:{workId:item.articleId}}" :title="$t('userAdmin.works.error.edit')">
            <i class="iconfont icon-bianji"></i>
          </router-link>
        </div>
        <div class="delete">
          <a href="javascript:;" :title="$t('userAdmin.works.error.delete')" @click="deleteArticle(item.articleId)">
            <i class="iconfont icon-shanchu"></i>
          </a>
        </div>
      </div>
    </div>
    <el-pagination
    v-if="!isEmpty && !noResponse"
    background
    layout="prev, pager, next"
    :total=pageTotal
    @current-change="handleCurrentChange(currentPage)"
    :current-page.sync = currentPage
    class="page">
  </el-pagination>
  </div>
</template>


<script>
    export default {
        name: "UserAdminMyWorks-errorCarder",
        data(){
            return{
                loading:"true",
                isEmpty:false,
                noResponse: true,
                baseURL:'http://localhost:8081/userAdmin/error/',
                baseURL2:'http://localhost:8081/userAdmin/getPages/error',
                baseURL3:'http://localhost:8081/userAdmin/delete/error/',
                contentData:'',
                pageTotal:0,
                currentPage:1,  // 当前页

                baseURL4:'http://localhost:8081/search/userAdminWork/error/',
                baseURL5:'http://localhost:8081/search/getUserAdminWorkPages/error/',
                isSearch:'',
                keyWord:'',
                // i18n:{
                //     edit: i18n.t("userAdmin.works.error.edit"),
                //     delete: i18n.t("userAdmin.works.error.delete")
                // }
            }
        },
        mounted(){
            this.$emit("component","error")
            this.getWorkInfo()
            // this.getPages()
        },
        methods:{
            searchInfo(keyWord){
                this.keyWord = keyWord
                this.axios.post(this.baseURL4 + keyWord +"/"+ 1).then(res=>{
                    this.isSearch = true
                    this.noResponse=false
                    if (res.data == false){
                        this.$message.error(this.$t('userAdmin.works.error.serviceUnusual'))
                    } else if (res.data == "empty") {
                        this.isEmpty = true
                        this.contentData = ""
                    } else {
                        this.isEmpty = false
                        this.contentData = res.data
                    }
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
                this.searchInfoPages(keyWord)

            },
            searchInfoPages(keyWord){
                this.axios.post(this.baseURL5 + keyWord).then(res=>{
                    this.pageTotal = res.data * 10
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
            },
            getWorkInfo(){
                this.axios.post(this.baseURL + 1).then(res=>{
                    this.isSearch = false
                    this.noResponse=false
                    if (res.data != "empty"){
                        this.isEmpty = false
                        this.contentData = res.data
                    }else {
                        this.isEmpty = true
                        this.contentData = ""
                    }
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
                this.getPages()
            },
            getPages(){
                this.axios.post(this.baseURL2).then(res=>{
                    this.pageTotal = res.data * 10
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
            },
            deleteArticle(articleId){
                this.$confirm(this.$t('userAdmin.works.error.confirm.info'), {
                    confirmButtonText: this.$t('userAdmin.works.error.confirm.confirm'),
                    cancelButtonText: this.$t('userAdmin.works.error.confirm.cancel'),
                    showClose: false,
                    type: 'warning'
                }).then(() => {
                    this.axios.post(this.baseURL3+articleId).then(res=>{
                        if (res.data ==true) {
                            this.successOpt(this.$t('userAdmin.works.error.confirm.successTip'))
                            this.getWorkInfo()
                        } else {
                            this.failOpt(this.$t('userAdmin.works.error.confirm.faiTip'))
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                }).catch(() => {
                    console.log(this.$t('userAdmin.works.error.confirm.cancelTip'))
                });
            },
            handleCurrentChange(currentPage){
                if (this.isSearch){
                    this.axios.post(this.baseURL4 + this.keyWord +"/"+ currentPage).then(res=>{
                        this.noResponse=false
                        if (res.data == false){
                            this.$message.error(this.$t('userAdmin.works.error.serviceUnusual'))
                        } else if (res.data == "empty") {
                            this.isEmpty = true
                            this.contentData = ""
                        } else {
                            this.isEmpty = false
                            this.contentData = res.data
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                } else {
                    this.axios.post(this.baseURL+currentPage).then(res=>{
                        this.noResponse=false
                        if (res.data != "empty"){
                            this.contentData = res.data
                            let target = document.getElementById("target").offsetTop
                            window.scrollTo({
                                top:target,
                                behavior: "smooth"
                            });
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                }
            },

            successOpt(message) {
                this.$notify({
                    title: this.$t('notify.success'),
                    message: message,
                    type: 'success'
                })
            },
            failOpt(message) {
                this.$notify.error({
                    title: this.$t('notify.error'),
                    message: message
                });
            }
        }
    }
</script>

<style scoped>
  .cardBox{
    margin: 0px auto;
    margin-top: 10px;
    width: 100%;
    /*width: 800px;*/
    border-radius: 3px;
    border: rgb(231, 231, 231) solid 1px;
    background-color: rgba(255, 255, 255, 0.9);
    position: relative;
    transition: 0.2s;
    letter-spacing: 1.5px;
  }
  .cardBox:hover{
    box-shadow: 0 0 5px rgb(214, 214, 214);
    transform:translateY(-1px);
  }
  .cardHead{
    width: 850px;
    height: 80px;
    /*background-color: tomato;*/
  }
  .cardHead-title{
    height: 50%;
    line-height: 45px;
    padding-left: 20px;
    padding-right: 45px;
    font-size: 15px;
    font-weight: bolder;
    color: rgb(0, 39, 71);
    /* 文字溢出处理 */
    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:1;
  }
  .cardHead-describ{
    padding-left: 20px;
    padding-right: 40px;
    line-height: 15px;
    font-size: 5px;
    color: rgb(131, 131, 131);
    /* 文字溢出处理 */
    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:2;
  }
  .cardDetial{
    width: 850px;
    height: 40px;
     /*background-color: thistle;*/
  }
  .cardDetial div{
    float: left;
    color: rgb(100, 100, 100);
    font-size: 10px;
  }
  .cardDetial-pubTime{
    width: 200px;
    height: 40px;
    margin-left: 280px;
    line-height: 40px;
    /* background-color: tomato; */
  }
  .cardDetial-pubTime i{
    color: rgb(119, 119, 119);
  }
  .cardDetial-act{
    width: 80px;
    height: 40px;
    line-height: 40px;
    /* background-color: rgb(204, 90, 70); */
  }
  .cardDetial-act i{
    color: rgb(223, 223, 0);
  }
  .cardDetial-star{
    width: 80px;
    height: 40px;
    line-height: 40px;
    /* background-color: rgb(177, 42, 19); */
  }
  .cardDetial-star i{
    color: rgb(211, 137, 0);
  }
  .cardDetial-classify{
    width: 200px;
    height: 40px;
    line-height: 40px;
    /* background-color: tomato; */
    /* 文字溢出处理 */
    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:1;
  }
  .cardDetial-classify i{
    color: rgb(16, 71, 189);
  }

  .controller{
    width: 50px;
    height: 100px;

    position: absolute;
    top: 10px;
    right: 6px;
    /* background-color: thistle; */
  }
  .edit, .delete{
    width: 50px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    /* background-color: wheat; */

  }
  .edit i{
    font-size: 20px;
    color: rgb(179, 179, 179);
  }
  .edit i:hover{
    color: rgb(0, 167, 0);
  }
  .delete i{
    font-size: 20px;
    color: rgb(179, 179, 179);
  }
  .delete i:hover{
    color: rgb(226, 17, 17);
  }
  .page{
    margin: 10px auto;
    margin-left: -10px;
  }
</style>
